var app = require('express')();
var http = require('http').Server(app)

//引入socket.io
var io = require('socket.io')(http);

//注册一个connection事件
io.on('connection',function(socket){
    //console.log('a user connected');
    socket.on('chat message',function(msg){
        console.log('message:'+msg);
        //做出响应，把接收到的消息再次发送到客户端
        io.emit('chat message',msg);
    })
})

app.get('/',function(req,res){
    // res.send('<h1>hello world!!!</h1>');
    //绝对路径
    res.sendFile(__dirname+'/index.html');
    //相对路径,也可以这样写
    //res.sendFile('/index.html');
});

http.listen(5000,function(){
    console.log('listening on 5000');
})